package com.terren.spider.entity.config;

import java.io.File;
import java.util.Properties;

import com.terren.spider.core.html.configuration.DynamicType;
import com.terren.spider.core.html.configuration.SpiderSchedulerType;
import com.terren.spider.entity.core.CatagoryType;
import com.terren.spider.util.common.CommonUtil;

public class SysConfig {
	/**
	 * common
	 */
	public static String PROJECT_PATH;// 
	public static String CONFIG_FILE_NAME = "config" + File.separator + "sysconfig.properties";
	//public static String CHROME_DRIVER = System.getProperty("user.dir") + File.separator + "src" + File.separator + "main" + File.separator + "resources" + File.separator + "chromedriver.exe";
	public static String CHROME_DRIVER;
	public static String LOG4J_PATH;

	public static String SCHEME_HELPURL_PATH = "com.terren.spider.core.html.scheme.helpurl.impl";
	public static String SCHEME_PAGINATION_PATH = "com.terren.spider.core.html.scheme.pagination.impl";
	public static String SCHEME_PROCESS_PATH = "com.terren.spider.core.html.scheme.process.impl";
	public static String SCHEME_SEARCH_PATH = "com.terren.spider.core.html.scheme.search.impl";
	public static String SCHEME_TARGETURL_PATH = "com.terren.spider.core.html.scheme.targeturl.impl";
	public static String SCHEME_BUILD_COOKIE_PATH = "com.terren.spider.core.html.scheme.cookie.impl";
	
	public static String SCHEME_PATH = "com.terren.spider.core.html.scheme.impl";//自定义方案实现类路径

	public static String URL_SPLIT = "，";// url匹配正则，多个正则时以半角逗号间隔
	
	
	
	
	

	// http://192.168.20.8:13003/\\?url=http://news.baidu.com/ns\\?.*&dynamic=true

	/**
	 * spider downloader
	 */
	public static String LAST_REDIRECT_URL = "last_redirect_url";// 最后跳转的链接
	/**
	 * spider processor
	 */
	public static String COLLECT_ITEM_KEY = "page_";
	public static String COLLECT_TOTAL_TARGET_URL = "total_url_target";
	public static String COLLECT_TOTAL_HELP_URL = "total_url_help";
	// public static String SEARCH_COLLECT_ITEM_KEY = "search_page_";//搜索页
	public static String COLLECT_ITEM_TITLE_KEY = "page_title";// 搜索页 标题
	public static String COLLECT_ITEM_PUBTIME_KEY = "page_pubtime";// 搜索页 发布时间
	public static String COLLECT_ITEM_SOURCE_KEY = "page_source";// 搜索页 来源
	public static String COLLECT_ITEM_BEGINTIME_KEY = "page_begintime";// 搜索页 时间条件
	public static String COLLECT_ITEM_ENDTIME_KEY = "page_endtime";// 搜索页 时间条件
	public static String COLLECT_ITEM_LAST_REDIRECT_URL = "page_last_redirect_url";// 最后跳转的链接
	public static String COLLECT_ITEM_AUTHOR_KEY = "page_author";// 搜索页 作者
	public static String COLLECT_ITEM_AUTHOR_URL_KEY = "page_author_url";// 搜索页 作者链接
	/**
	 * spider scheduler
	 */
	public static String FILE_CACHE_SCHEDULER_PATH;// FileCacheQueueScheduler 保存路径

	/***
	 * configuration
	 */
	public static String VERSION = "1.0";
	public static Boolean DEFUALT_SAVE_TO_DB = true;
	public static Boolean DEFUALT_SAVE_TO_JSON = false;
	public static Boolean DEFUALT_SAVE_TO_HTML = false;
	public static Boolean DEFUALT_SAVE_BATCH = true;
	public static Integer DEFUALT_SAVE_BATCH_COUNT = 200;// 批处理条数

	public static Integer RETRY_TIMES = 3;// 重试次数
	public static Integer SLEEP_TIME = 5000;// 抓取间隔
	public static Integer CYCLE_RETRY_TIMES = 0;// 抓取间隔
	public static Integer RETRY_SLEEP_TIME = 1000;//
	public static Integer TIME_OUT = 60000;//
	public static Integer PROXY_TIME_OUT = 30;//代理 timeout
	public static Integer THREAD_NUM = 10;// 线程数
	public static Boolean DISABLE_COOKIE_MANAGEMENT = false;
	public static Boolean USER_GZIP = true;
	public static Boolean ENTRY_USE_PROXY = false; // 是否使用代理
	public static Boolean CONTENT_USE_PROXY = false; // 目标页是否使用代理
	public static SpiderSchedulerType SCHEDULER_TYPE = SpiderSchedulerType.QueueScheduler;// URL管理的组件
																							// Scheduler包括两个作用：对待抓取的URL队列进行管理。对已抓取的URL进行去重

	public static DynamicType URL_DYNAMIC = DynamicType.DYNAMIC_DISENABLE;
	public static CatagoryType CATAGORY_TYPE = CatagoryType.NEWS;// 爬取类型
	public static String CHARTSET = "UTF-8";

	/***
	 * search engine
	 */
	public static Integer RECORD_LIMIT = 1000;// 搜索引擎抓取结果的条数
	public static Integer RECORD_SIZE = 10;// 每页显示的条目
	public static Integer MORE_SIZE = 0;// 爬取条目数富余量（在返回条目数基础上多加的爬取数据，预防个别url爬取不到造成爬取数据量过少）

	/**
	 * abuyun proxy
	 */

	// 代理服务器
	public static String ABUYUN_PROXY_HOST;
	public static Integer ABUYUN_PROXY_PORT;
	// 代理隧道验证信息
	public static String ABUYUN_PROXY_USER;
	public static String ABUYUN_PROXY_PASS;
	public static String ABUYUN_PROXY_SWITCH_IP_KEY = "Proxy-Switch-Ip";
	public static String ABUYUN_WHITE_LIST_STRATEGY = "abuyun.whiteList";
	public static String ABUYUN_BLACK_LIST_STRATEGY = "abuyun.blackList";

	/**
	 * spider cookie
	 */
	public static String COOKIE_WHITE_LIST_STRATEGY = "cookie.whiteList";
	public static String COOKIE_BLACK_LIST_STRATEGY = "cookie.blackList";
	
	
	
	/**
	 * data handle 数据处理
	 */
	public static String SIMILAR_URL;//文章相似度接口地址
	public static String SENTIMENT_TAG_URL;//情感分析接口地址

	static {
		/**
		 * 项目路径
		 */
		PROJECT_PATH = CommonUtil.getProjectPath(SysConfig.class)+File.separator;
		/**
		 * webdriver 浏览器驱动
		 */
		CHROME_DRIVER = PROJECT_PATH + "chromedriver.exe";
		System.setProperty("webdriver.chrome.driver",SysConfig.CHROME_DRIVER);
		/**
		 * log4j
		 */
		LOG4J_PATH =  PROJECT_PATH+"config"+File.separator+"log4j"+File.separator+"log4j.xml";
		/**
		 * 缓存目录
		 */
		FILE_CACHE_SCHEDULER_PATH = PROJECT_PATH + "temp" + File.separator + "cache"
				+ File.separator;

		/**
		 * 配置文件
		 */
		Properties properties = CommonUtil.getSysConfigProperties();
		/***** 读取配置文件 *****/
		String abuyun_proxy_host = properties.getProperty("abuyun.host");
		if (null != abuyun_proxy_host) {
			ABUYUN_PROXY_HOST = abuyun_proxy_host;
		}
		String abuyun_proxy_port = properties.getProperty("abuyun.port");
		if (null != abuyun_proxy_port) {
			ABUYUN_PROXY_PORT = Integer.valueOf(abuyun_proxy_port);
		}
		String abuyun_proxy_user = properties.getProperty("abuyun.user");
		if (null != abuyun_proxy_user) {
			ABUYUN_PROXY_USER = abuyun_proxy_user;
		}
		String abuyun_proxy_pass = properties.getProperty("abuyun.password");
		if (null != abuyun_proxy_pass) {
			ABUYUN_PROXY_PASS = abuyun_proxy_pass;
		}

		
		String similar_url = properties.getProperty("similar.url");
		if (null != similar_url) {
			SIMILAR_URL = similar_url;
		}
		
		String sentiment_tag_url = properties.getProperty("sentiment_tag.url");
		if (null != sentiment_tag_url) {
			SENTIMENT_TAG_URL = sentiment_tag_url;
		}
	}
}